<template>
	<view class="index">
		<ugo-search></ugo-search>
		<view class="swiper">
			<swiper>
				<swiper-item v-for="item in list" :key="item.goods_id">
					<navigator url=item.navigator_url>
						<image :src="item.image_src"></image>
					</navigator>
				</swiper-item>
			</swiper>
		</view>
		<view class="navs">
			<navigator v-for="(item, index) in catList" :key="index"
				:open-type="item.navigator_url ? 'switchTab' : 'navigate'"
				:url="item.navigator_url ? '/pages/category/category' : '/packageone/list/list?query=' + item.name">
				<image :src="item.image_src" />
			</navigator>
		</view>


		<!-- 栏目楼层 -->
		<view class="floors" v-for=" (item, index) in FloorList">
			<!-- 1 -->
			<view class="floor">
				<!-- title -->
				<view class="ftitle">
					<image :src="item.floor_title.image_src" />
				</view>
				<!-- pics -->
				<view class="fitems">
					<navigator class="fitem" :url="'/packageone/list/list?query=' + prd.name"
						v-for="prd in item.product_list" :key="prd.name">
						<image :src="prd.image_src" />
					</navigator>
				</view>
			</view>
		</view>
		<view v-if="isTop" @click="goTop" class="goTop icon-top"></view>
	</view>
</template>
<script>
	// import MyCom  from '../../my-component/my-com.vue'
	export default {
		data() {
			return {
				// 轮播图
				list: [],
				// 菜单导航
				catList: [],
				// 时尚女装
				FloorList: [],
				isTop: false
			}
		},
		async onLoad() {
			this.getSwiper()
			this.getCatList()
			this.getFloorList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			// 发请求获取最新数据
			Promise.all([this.getSwiper(), this.getCatList(), this.getFloorList()]).then(res => {
				// Promise.all([]) 的数组中的所有 Promise 都成功,就会执行
			}).catch(err => {

			}).finally(() => {
				// 手动调用关闭下拉刷新
				uni.stopPullDownRefresh()
			})
		},
		methods: {
			// 获取轮播图数据
			async getSwiper() {
				const res = await this.request({
					url: '/home/swiperdata'
				})
				// console.log(res)
				this.list = res.message
			},
			// 导航菜单
			async getCatList() {
				const res = await this.request({
					url: '/home/catitems'
				})
				// console.log(res.message)
				this.catList = res.message
			},
			// 时尚女装
			async getFloorList() {
				const res = await this.request({
					url: '/home/floordata'
				})
				// console.log(res.message)
				this.FloorList = res.message
			},
			// 监听滚动条的位置
			onPageScroll({scrollTop}) {
				// console.log(scrollTop)
				// 如果滚动的距离 >= 整体的高度 50% 就显示返回顶部的按钮
				const {windowHeight} = uni.getSystemInfoSync()
				this.isTop = scrollTop > windowHeight * 0.5
			},
			// 返回顶部
			goTop() {
				uni.pageScrollTo({
					scrollTop: 0
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		.swiper {

			swiper,
			image {
				width: 750rpx;
				height: 340rpx;
			}
		}

		// 功能导航
		.navs {
			display: flex;
			padding: 30rpx;
			background: #fff;
			justify-content: space-around;

			navigator,
			image {
				display: block;
				width: 128rpx;
				height: 140rpx;
			}
		}

		.floors {
			.ftitle {
				padding-top: 30rpx;
				background: #f4f4f4;

				image {
					width: 750rpx;
					height: 60rpx;
				}
			}

			.fitems {
				display: flex;
				flex-wrap: wrap;
				justify-content: flex-start;

				.fitem {
					box-sizing: border-box;
					width: 250rpx;
					height: 200rpx;
					padding: 5rpx;

					image {
						width: 240rpx;
						height: 190rpx;
						// 750 / 3 = 250
					}
				}
			}
		}

		.goTop {
			position: fixed;
			bottom: 30rpx;
			/* #ifdef H5 */
			bottom: 65px;
			/* #endif */
			right: 30rpx;

			display: flex;
			justify-content: center;
			align-items: center;
			width: 100rpx;
			height: 100rpx;
			font-size: 48rpx;
			color: #666;
			border-radius: 50%;
			background-color: rgba(255, 255, 255, 0.8);
		}
	}
</style>